﻿// JScript File
function popupsong(PresentationId)
{
   Window= window.open('Default.aspx?page=MusicPlayer&PresentationId='+PresentationId, 'popupsong', 'width=600,height=600', '');
   Window.focus();
}
function popupAlbum(AlbumId)
{
   Window= window.open('Default.aspx?page=MusicPlayer&AlbumId='+AlbumId, 'popupsong', 'width=600,height=600', '');
   Window.focus();
}
function popupPlaylist()
{
   Window= window.open('Default.aspx?page=MusicPlayer&URLPlaylist=true', 'popupsong', 'width=600,height=600', '');
   Window.focus();
}
//end popup----------------------------------------------------------------------------------------------
//begin cookie------------------------------------------------------------------------------------------
function SetCookie(key,value)
{
    var cookieDate=new Date(2011,01,04,19,30,30);
    document.cookie=key+"="+escape(value)+"; expires="+cookieDate.toGMTString()+"; path=/";
    alert("document.cookie: " + document.cookie);
};
function ReadCookie(key)
{
    var cookie=document.cookie;
    var first=cookie.indexOf(key+"=");
    if(first>=0)
        {
            var str=cookie.substring(first,cookie.length);
            var last=str.indexOf(";");
            if(last<0)last=str.length;
            str=str.substring(0,last).split("=");
            return unescape(str[1]);
        }
    else{return null;}
};
function EraseCookie(key)
{
    var cookieDate=new Date(2011,01,04,19,30,30);
    document.cookie=key+"= ; expires="+cookieDate.toGMTString()+"; path=/";
} 
     
var count = 0;
function Add(id)
{
    ++count;
    document.getElementById('countCart').innerHTML  = count; 
    var str= new Array();
    if(ReadCookie('MCMPlaylist')!=""&&ReadCookie('MCMPlaylist')!=null)
	    str=ReadCookie('MCMPlaylist').split('|');
    var i=0
	for(j=0;j<str.length;j++)
	{
	    if(id==str[j])
	        i=i+1;
	}
	if(i==0)
    {
        if(ReadCookie('MCMPlaylist')==""||ReadCookie('MCMPlaylist')==null)
        {
            str=id;
        }
        else
        {
            str=ReadCookie('MCMPlaylist')+'|'+id;
        }	    
	    SetCookie('MCMPlaylist',str);
    }
}

function AddCookie(id)
{
    Add(id);
   // DoPlayListPostBack();
    var x= alert('Bạn đã thêm một sản phẩm vào giỏ hàng'); 
    setTimeout("x.window.close()", 2000);      
}

function RemoveCookie(id)
{
	var str= new Array();
	str=ReadCookie('MCMPlaylist').split('|');
	EraseCookie('MCMPlaylist')
	for(j=0;j<str.length;j++)
	{
		if(str[j]!=id)
			Add(str[j]);
	}
	//DoPlayListPostBack();
	alert('Bạn đã loại một sản phẩm khỏi giỏ hàng');
	setTimeout("window.close()", 2000);
}
//end cookie------------------------------------------------------------------------------------------
